<html>
<head>
    <title>物流快递 - 后台</title>
    <link href="/static/css/semantic.css" rel="stylesheet"/>
    <style>
body{font-family: "Microsoft YaHei" !important;}
.ui.menu .item img.logo {
    margin-right: 1.5em;
}
.main.container {
    margin-top: 7em;
}
.wireframe {
    margin-top: 2em;
}
.ui.footer.segment {
    margin: 5em 0em 0em;
    padding: 5em 0em;
}
    </style>
</head>
<body>
<#if me?? && me.type=='M'>
<div class="ui fixed inverted menu">
    <div class="ui container">
        <a href="#" class="header item">
            欢迎使用物流管理系统
        </a>
        <a href="/users" class="item">员工管理</a>
        <a href="/region" class="item">地区管理</a>
        <a href="/sites" class="item">站点管理</a>
        <a href="/waybill" class="item">货单管理</a>
        <a href="/login" class="item">退出</a>

    </div>
</div>
</#if>

<div class="ui main text container"style="
    max-width: 900px!important;
">
    <table class="ui celled striped table">
        <thead>
        <tr><th colspan="4">货单管理
            <button class="button ui primary" onclick="$('.ui.modal.m2').modal('show');">添加</button>
        </th>
        </tr></thead>
        <tbody>

        <#list list as i>
        <tr>
            <td class="collapsing">单号： <a href="/wb/detail/${i.id}">${i.id} </a></td>
            <td>发件人：${i.from}</td>
            <td>
                <#if i.status == 'D'>待发货</#if>
                <#if i.status == 'Y'>已揽件</#if>
                <#if i.status == 'Q'>已签收</#if>
            </td>
            <td class="right aligned collapsing">
                <button class="button ui green" onclick="update('${i.id}','Y')">发货</button>
                <button class="button ui blue" onclick="update('${i.id}','Q')">签收</button>
                <button class="button ui orange" onclick="$('.ui.modal.m1').modal('show');wbId='${i.id}'">中转</button>
                <button class="button ui red" onclick="del('${i.id}')">删除</button>
            </td>
        </tr>
        </#list>
        </tbody>
    </table></div>
<div class="ui modal m1" style="width: 300px; padding: 15px;margin-left: -200px">
    <form class="ui form five" method="post">
        <div class="field">
            <input type="text" id="location" placeholder="物流位置">
        </div>
        <div class="field">
            <input type="text" id="desc" placeholder="描述">
        </div>
        <button class="ui button primary" type="button" onclick="addzz()">提交</button>
        <button class="ui button" type="button" onclick="$('.ui.modal').modal('hide');">取消</button>
    </form>
</div>
<div class="ui modal m2" style="width: 300px; padding: 15px;margin-left: -200px">
    <form class="ui form five" method="post">
        <div class="field">
            <input type="text" id="from" placeholder="寄件人姓名">
        </div>
        <div class="field">
            <input type="text" id="departure" placeholder="始发地">
        </div>
        <div class="field">
            <input type="text" id="companyName" placeholder="单位名称">
        </div>
        <div class="field">
            <input type="text" id="address" placeholder="寄件地址">
        </div>
        <div class="field">
            <input type="text" id="phone" placeholder="联系电话">
        </div>
        <div class="field">
            <input type="text" id="postalCode" placeholder="邮政编码">
        </div>
        <div class="field">
            <input type="text" id="to" placeholder="收件人">
        </div>
        <div class="field">
            <input type="text" id="toPhone" placeholder="收件人号码">
        </div>
        <div class="field">
            <input type="text" id="toCompanyName" placeholder="收件人单位名称">
        </div>
        <div class="field">
            <input type="text" id="toAddress" placeholder="收件地址">
        </div>
        <button class="ui button primary" type="button" onclick="add()">提交</button>
        <button class="ui button" type="button" onclick="$('.ui.modal.m2').modal('hide');">取消</button>
    </form>
</div>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/semantic.min.js"></script>
<script type="text/javascript">
    function add() {
        $.post('/wb/add',{
            from:$('#from').val(),
            departure: $('#departure').val(),
            companyName: $('#companyName').val(),
            address: $('#address').val(),
            phone: $('#phone').val(),
            postalCode: $('#postalCode').val(),
            to: $('#to').val(),
            toPhone: $('#toPhone').val(),
            toCompanyName: $('#toCompanyName').val(),
            toAddress: $('#toAddress').val(),
        },function (data) {
            alert('添加成功');
            location.reload();
        })
    }
    function addzz() {
        $.post('/wb/addzz',{
            waybillId:wbId,
            location:$('#location').val(),
            desc:$('#desc').val(),
        },function (data) {
            alert('添加成功');
            location.reload();
        })
    }
    function del(id) {
        $.post('/wb/delete/'+id,function (data) {
            alert('删除成功');
            location.reload();
        })
    }
    function update(id,status) {
        $.post('/wb/updateStatus',{
            id:id,
            status:status
        },function () {
            location.reload();
        })
    }
</script>
</body>
</html>